package com.mall.user.services;

import com.mall.user.ILoginService;
import com.mall.user.constants.SysRetCodeConstants;
import com.mall.user.dto.CheckAuthRequest;
import com.mall.user.dto.CheckAuthResponse;
import com.mall.user.utils.JwtTokenUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.stereotype.Component;

@Component
@Service
public class LoginServiceImpl implements ILoginService {
    @Override
    public CheckAuthResponse validToken(CheckAuthRequest checkAuthRequest) {
        checkAuthRequest.requestCheck();
        CheckAuthResponse checkAuthResponse = new CheckAuthResponse();
        JwtTokenUtils jwtTokenUtils = JwtTokenUtils.builder().build();
        jwtTokenUtils.setToken(checkAuthRequest.getToken());
        String s = jwtTokenUtils.freeJwt();
        if (StringUtils.isBlank(s)) {
            checkAuthResponse.setCode(SysRetCodeConstants.TOKEN_VALID_FAILED.getCode());
            checkAuthResponse.setMsg(SysRetCodeConstants.TOKEN_VALID_FAILED.getMessage());
            return checkAuthResponse;
        }
        checkAuthResponse.setUserinfo(s);
        checkAuthResponse.setCode(SysRetCodeConstants.SUCCESS.getCode());
        checkAuthResponse.setMsg(SysRetCodeConstants.SUCCESS.getMessage());
        return checkAuthResponse;
    }
}
